package com.example.smart_light.socket;

import javax.xml.crypto.Data;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.List;

public class SocketService {


	public static void sendToAll(String cmd){
		List<Socket> socketList = ConnSocket.getSocketList();
		for(Socket socket:socketList){
			try {
				DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
				dataOutputStream.writeUTF(cmd);
				dataOutputStream.flush();
			} catch (IOException e) {
				System.out.println(socket.getRemoteSocketAddress()+"下线");
				socketList.remove(socket);
			}
		}

	}

}